<?php
include_once '../Login/databaseconnection.php';
$q=$_GET['q'];
$hint='';
$exists="";
$ele=explode(",",$q);
$Attriute=$ele[0];
$Access_Type=$ele[1];
$T_value=$ele[2];
$Type=$ele[3];
$sch=mysql_query("SELECT * FROM school WHERE School_Id=".$T_value."");
if($row=mysql_fetch_array($sch))
{
$school=$row['Name'];
}

if($Attriute=="In_Charge_Name")
{
$NIC="";
$heading="Teacher in charge of ".$school;
$table='teacher';
$get_in_char=mysql_query("SELECT * FROM user WHERE Access_Type='Teacher in Charge'");
while($row_in_char=mysql_fetch_array($get_in_char))
{
if(empty($NIC))
{
$NIC="'".$row_in_char['NIC_Number']."'";
}
else
{
$NIC=$NIC.",'".$row_in_char['NIC_Number']."'";
}
}
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND T_NIC_Number IN(".$NIC.")");
}

if($Attriute=="Male_Teachers")
{
$heading="All male teachers of ".$school;
$table='teacher';
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND Gender='Male'");
}

if($Attriute=="Female_Teachers")
{
$heading="All female teachers of ".$school;
$table='teacher';
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND Gender='Female'");
}

if($Attriute=="Res_Persons")
{
$heading="All resource people of ".$school;
$All_res_per="";
$All_Teachers="";
$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
if($All_Teachers!="")
{
$get_res_per=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number IN(".$All_Teachers.")");
while($row_res_per=mysql_fetch_array($get_res_per))
{
if(empty($All_res_per))
{
$All_res_per='"'.$row_res_per['T_NIC_Number'].'"';
}
else
{
$All_res_per=$All_res_per.',"'.$row_res_per['T_NIC_Number'].'"';
}
}
}
$table='teacher';
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND T_NIC_Number IN(".$All_res_per.")");
}

if($Attriute=="Graduate_Teachers")
{
$heading="All graduate teachers of ".$school;
$getval=mysql_query("SELECT * FROM teacher WHERE Academic_Qualifications LIKE '%deg_%' AND School_Id='".$T_value."'");
$table='teacher';
}

if($Attriute=="No_Appo_Teachers")
{
$Appo_Sub=$ele[4];
$getval=mysql_query("SELECT * FROM teacher WHERE Appointed_Subject LIKE '".$Appo_Sub."%' AND School_Id='".$T_value."'");
$table='teacher';
$heading="All ".$Appo_Sub." teachers of ".$school;
}

if($Attriute=="Tra_Teachers")
{
$Training=$ele[4];
$All_res_per="";
$All_Teachers="";
$getTraId=mysql_query("SELECT * FROM training WHERE Training_Name='".$Training."'");
if($r_ID=mysql_fetch_array($getTraId))
{
$Training_Id=$r_ID['Training_Id'];
}
$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
if($All_Teachers!="")
{
$get_res_per=mysql_query("SELECT * FROM training_details WHERE Training_Id='".$Training_Id."' AND Teacher_NIC IN(".$All_Teachers.")");
while($row_res_per=mysql_fetch_array($get_res_per))
{
if(empty($All_res_per))
{
$All_res_per='"'.$row_res_per['Teacher_NIC'].'"';
}
else
{
$All_res_per=$All_res_per.',"'.$row_res_per['Teacher_NIC'].'"';
}
}
}
$table='teacher';
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND T_NIC_Number IN(".$All_res_per.")");
$heading="All ".$Training." trained teachers of ".$school;
}

if($Attriute=="Resource_Persons")
{
$Training=$ele[4];
$All_res_per="";
$All_Teachers="";
$All_res_pers="";
$getTraId=mysql_query("SELECT * FROM training WHERE Training_Name='".$Training."'");
if($r_ID=mysql_fetch_array($getTraId))
{
$Training_Id=$r_ID['Training_Id'];
}
$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
if($All_Teachers!="")
{
$get_res_per=mysql_query("SELECT * FROM training_details WHERE Training_Id='".$Training_Id."' AND Teacher_NIC IN(".$All_Teachers.")");
while($row_res_per=mysql_fetch_array($get_res_per))
{
if(empty($All_res_per))
{
$All_res_per='"'.$row_res_per['Teacher_NIC'].'"';
}
else
{
$All_res_per=$All_res_per.',"'.$row_res_per['Teacher_NIC'].'"';
}
}
}
if($All_res_pers!="")
{
$get_res_pers=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number IN(".$All_res_per.")");
while($row_res_pers=mysql_fetch_array($get_res_pers))
{
if(empty($All_res_pers))
{
$All_res_pers='"'.$row_res_pers['T_NIC_Number'].'"';
}
else
{
$All_res_pers=$All_res_pers.',"'.$row_res_pers['T_NIC_Number'].'"';
}
}
}
$table='teacher';
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND T_NIC_Number IN(".$All_res_pers.")");
$heading="All ".$Training." trained resource people of ".$school;
}

if($Attriute=="Tra_Male_Teachers")
{
$Training=$ele[4];
$All_res_per="";
$All_Teachers="";
$getTraId=mysql_query("SELECT * FROM training WHERE Training_Name='".$Training."'");
if($r_ID=mysql_fetch_array($getTraId))
{
$Training_Id=$r_ID['Training_Id'];
}
$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND Gender='Male'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
if($All_Teachers!="")
{
$get_res_per=mysql_query("SELECT * FROM training_details WHERE Training_Id='".$Training_Id."' AND Teacher_NIC IN(".$All_Teachers.")");
while($row_res_per=mysql_fetch_array($get_res_per))
{
if(empty($All_res_per))
{
$All_res_per='"'.$row_res_per['Teacher_NIC'].'"';
}
else
{
$All_res_per=$All_res_per.',"'.$row_res_per['Teacher_NIC'].'"';
}
}
}
$table='teacher';
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND T_NIC_Number IN(".$All_res_per.")");
$heading="All ".$Training." trained male teachers of ".$school;
}

if($Attriute=="Tra_Female_Teachers")
{
$Training=$ele[4];
$All_res_per="";
$All_Teachers="";
$getTraId=mysql_query("SELECT * FROM training WHERE Training_Name='".$Training."'");
if($r_ID=mysql_fetch_array($getTraId))
{
$Training_Id=$r_ID['Training_Id'];
}
$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND Gender='Female'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
if($All_Teachers!="")
{
$get_res_per=mysql_query("SELECT * FROM training_details WHERE Training_Id='".$Training_Id."' AND Teacher_NIC IN(".$All_Teachers.")");
while($row_res_per=mysql_fetch_array($get_res_per))
{
if(empty($All_res_per))
{
$All_res_per='"'.$row_res_per['Teacher_NIC'].'"';
}
else
{
$All_res_per=$All_res_per.',"'.$row_res_per['Teacher_NIC'].'"';
}
}
}
$table='teacher';
$getval=mysql_query("SELECT * FROM teacher WHERE School_Id='".$T_value."' AND T_NIC_Number IN(".$All_res_per.")");
$heading="All ".$Training." trained female teachers of ".$school;
}

if($Attriute=="Total_Labs")
{
$heading="All labs of ".$school;
$table='lab';
$getval=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."'");
}

if($Attriute=="T_Labs")
{
$La_Type=$ele[4];
$table='lab';
$getval=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Type='".$La_Type."'");
$heading="All ".str_replace("Lab","",$La_Type)." labs of ".$school;
}

if($Attriute=="Lan_Ava_Labs")
{
$La_Type=$ele[4];
$All_Labs="";
$All_LLabs="";
$table='lab';
$all_labs=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Type='".$La_Type."'");
while($rowall=mysql_fetch_array($all_labs))
{
if(empty($All_Labs))
{
$All_Labs='"'.$rowall['Lab_Id'].'"';
}
else
{
$All_Labs=$All_Labs.',"'.$rowall['Lab_Id'].'"';
}
}
$lan_avai=mysql_query("SELECT * FROM network WHERE Availability_Of_LAN='Yes' AND School_Id='".$T_value."' AND Lab_Id in(".$All_Labs.")");
while($rowlan_avail=mysql_fetch_array($lan_avai))
{
if(empty($All_LLabs))
{
$All_LLabs='"'.$rowlan_avail['Lab_Id'].'"';
}
else
{
$All_LLabs=$All_LLabs.',"'.$rowlan_avail['Lab_Id'].'"';
}
}
$getval=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Id in(".$All_LLabs.")");
$heading="All lan available ".str_replace("Lab","",$La_Type)." labs of ".$school;
}

if($Attriute=="Wan_Ava_Labs")
{
$La_Type=$ele[4];
$All_Labs="";
$All_WLabs="";
$table='lab';
$all_labs=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Type='".$La_Type."'");
while($rowall=mysql_fetch_array($all_labs))
{
if(empty($All_Labs))
{
$All_Labs='"'.$rowall['Lab_Id'].'"';
}
else
{
$All_Labs=$All_Labs.',"'.$rowall['Lab_Id'].'"';
}
}
$wan_avai=mysql_query("SELECT * FROM network WHERE WAN_Connection_Type!='' AND Speed_Of_WAN!='' AND School_Id='".$T_value."' AND Lab_Id in(".$All_Labs.")");
while($rowwan_avail=mysql_fetch_array($wan_avai))
{
if(empty($All_WLabs))
{
$All_WLabs='"'.$rowwan_avail['Lab_Id'].'"';
}
else
{
$All_WLabs=$All_WLabs.',"'.$rowwan_avail['Lab_Id'].'"';
}
}
$getval=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Id in(".$All_WLabs.")");
$heading="All wan available ".str_replace("Lab","",$La_Type)." labs of ".$school;
}

if($Attriute=="Number_Of_Labs")
{
$supp_index=$ele[4];
$La_Type=$ele[5];
$All_Labs="";
$All_SLabs="";
$lan_Suppliers="";
$table='lab';
$all_labs=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Type='".$La_Type."'");
while($rowall=mysql_fetch_array($all_labs))
{
if(empty($All_Labs))
{
$All_Labs='"'.$rowall['Lab_Id'].'"';
}
else
{
$All_Labs=$All_Labs.',"'.$rowall['Lab_Id'].'"';
}
}
$lab_net=mysql_query("SELECT DISTINCT(LAN_Supplier) FROM network WHERE School_Id='".$T_value."' AND Lab_Id in(".$All_Labs.")");
if($lab_net)
{
while($row_lab_net=mysql_fetch_array($lab_net))
{
if($row_lab_net['LAN_Supplier']!="")
{
if(empty($lan_Suppliers))
{
$lan_Suppliers=$row_lab_net['LAN_Supplier'];
}
else
{
$lan_Suppliers=$lan_Suppliers.','.$row_lab_net['LAN_Supplier'];
}
}
}
}
$alllan_Suppliers=explode(",",$lan_Suppliers);
$supplier=$alllan_Suppliers[$supp_index];
$lab_supplier=mysql_query("SELECT * FROM network WHERE School_Id='".$T_value."' AND LAN_Supplier='".$supplier."' AND Lab_Id in(".$All_Labs.")");
while($rowlan_supp=mysql_fetch_array($lab_supplier))
{
if(empty($All_SLabs))
{
$All_SLabs='"'.$rowlan_supp['Lab_Id'].'"';
}
else
{
$All_SLabs=$All_SLabs.',"'.$rowlan_supp['Lab_Id'].'"';
}
}
$getval=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Id in(".$All_SLabs.")");
$heading="All lan available ".str_replace("Lab","",$La_Type)." labs of ".$school.",lan supplied by ".$supplier;
}

if($Attriute=="Number_Of_Equipments")
{
$table="resource_details";
$All_Labs="";
$coun=count($ele);
$res_index=$ele[4];
$La_Type=$ele[$coun-1];
$attr_index=$res_index+5;
$attr=$ele[$attr_index];
$splited=explode("_",$attr);
$Organization=$splited[0];
$Res_Id=$splited[1];
$Lab_Ids="";
$all_labs=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Type='".$La_Type."'");
while($rowall=mysql_fetch_array($all_labs))
{
if(empty($All_Labs))
{
$All_Labs='"'.$rowall['Lab_Id'].'"';
}
else
{
$All_Labs=$All_Labs.',"'.$rowall['Lab_Id'].'"';
}
}
$res_type=mysql_query("SELECT * FROM resource WHERE Resource_Id='".$Res_Id."'");
if($row_res_type=mysql_fetch_array($res_type))
{
$Resource_Type=$row_res_type['Resource_Type'];
}

$getval=mysql_query("SELECT * FROM resource_details WHERE Name_Of_Supplier='".$Organization."' AND Resource_Id='".$Res_Id."' AND School_Id='".$T_value."' AND Lab_Id in (".$All_Labs.")");
/*if($lab_res)
{
while($rowlabs=mysql_fetch_array($lab_res))
{
if(empty($Lab_Ids))
{
$Lab_Ids='"'.$rowlabs['Lab_Id'].'"';
}
else
{
$Lab_Ids=$Lab_Ids.',"'.$rowlabs['Lab_Id'].'"';
}
}
}
$getval=mysql_query("SELECT * FROM lab WHERE School_Id='".$T_value."' AND Lab_Id in(".$Lab_Ids.")");*/
$heading="All ".$Resource_Type."s of ".$school.",supplied by ".$Organization;
}

$resultcol=mysql_query("SHOW COLUMNS FROM ".$table);
while($rowcolu=mysql_fetch_row($resultcol))
{
if(empty($colnamearray))
{
$colnamearray=$rowcolu[0];
}
else
{
$colnamearray=$colnamearray.",".$rowcolu[0];
}
}
$cnamearray=explode(",",$colnamearray);

if($Attriute=="Tra_Teachers"||$Attriute=="Tra_Male_Teachers"||$Attriute=="Tra_Female_Teachers")
{
$hint=$hint.'<div id="modal_down">';
}
else if($Attriute=="Number_Of_Equipments")
{
$hint=$hint.'<div id="modal_middle_down2">';
}
else if($Attriute=="Number_Of_Labs"||$Attriute=="Wan_Ava_Labs"||$Attriute=="Lan_Ava_Labs"||$Attriute=="Total_Labs"||$Attriute=="T_Labs")
{
$hint=$hint.'<div id="modal_middle_down">';
}
else if($Attriute=="Teachers_In_Training"||$Attriute=="Trained_Teachers")
{
$hint=$hint.'<div id="modal_middle">';
}
else
{
$hint=$hint.'<div id="modal">';
}
$hint=$hint.'<div id="heading">'.$heading.'<input type="button" class="del_photo_empty red close" value="Exit" onclick="clearpopbox()"/></div><div id="photos_link">';

if(($getval))
{
if(mysql_num_rows($getval)>=1)
{
$hint=$hint.'<div style="width:100%; height:100%; overflow-x:scroll; overflow-y:scroll;">';
}
$hint=$hint.'<table width="100%" border="1" class="tablefontv"><tr bgcolor="#585C3F">';
for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		if($val!="Lab_Id"&&$val!="Resource_Id"&&$val!="School_Id"&&$val!="Last_Updated_Date")
  {
	$hint=$hint.'<td>'.$th_cname.'</td>';
  }
    }
	$hint=$hint.'</tr>';
	while($row=mysql_fetch_array($getval))
  {
	$hint=$hint.'<tr bgcolor="#CBCFB5">';
for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
		if($val!="Lab_Id"&&$val!="Resource_Id"&&$val!="School_Id"&&$val!="Last_Updated_Date")
  {
       $hint=$hint.'<td>';
		$hint=$hint.str_replace("deg_"," ",$valu);
		$hint=$hint.'</td>';
  }
	}
	$hint=$hint.'</tr>';
	}
	$hint=$hint.'</table>';
	if(mysql_num_rows($getval)>=1)
{
$hint=$hint.'</div>';
}
}
/*$get_tea_in_cha=mysql_query("SELECT * FROM user WHERE Access_Type='Teacher in Charge'");
while($in_cha=mysql_fetch_array($get_tea_in_cha))
{
$In_Charge=$in_cha['NIC_Number'];
$get_tea_sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$In_Charge'");
if($in_cha_sch=mysql_fetch_array($get_tea_sch))
{
$Sch_Id=$in_cha_sch['School_Id'];
if($Sch_Id==$School_Id)
{
$In_Charge_F_N=$in_cha_sch['First_Name'];
$In_Charge_L_N=$in_cha_sch['Last_Name'];
}
}
}
$In_Charge_Name=$In_Charge_F_N." ".$In_Charge_L_N;
*/
$hint=$hint.'</div></div>';
if($hint=="")
{
$response='<div id="modal_empty"><div id="heading_empty"><input type="button" class="del_photo_empty red close" value="Exit" onclick="clearpopbox()"/></div><div id="photos_link_empty">';
$response=$response.'<img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry there are no results for you!</font><a href="index.php" class="del_photo_empty red close">Ok!</a></div></div>';
}
else
{
$response=$hint;
}
echo $response;
?>